package org.dromara.business.utils;

public class PasswordStrengthChecker {

    public enum Strength {
        WEAK, MEDIUM, STRONG, VERY_STRONG
    }

    public static Strength checkStrength(String password) {
        if (password == null || password.length() < 8) {
            return Strength.WEAK;
        }

        int score = 0;

        // 长度加分
        if (password.length() >= 12) score++;
        if (password.length() >= 16) score++;

        // 包含数字
        if (password.matches(".*\\d.*")) score++;

        // 包含小写字母
        if (password.matches(".*[a-z].*")) score++;

        // 包含大写字母
        if (password.matches(".*[A-Z].*")) score++;

        // 包含特殊字符
        if (password.matches(".*[!@#$%^&*()\\-_=+\\[\\]{}|;:,.<>?].*")) score++;

        // 判断强度
        if (score < 3) {
            return Strength.WEAK;
        }
        if (score < 5) {
            return Strength.MEDIUM;
        }
        return Strength.STRONG;
    }

    public static void main(String[] args) {
        System.out.println(checkStrength(PasswordGenerator.generateRobotPassword()));
    }
}
